/*

#include <iostream>
#include <string>
using namespace std;

int main()
{
    int T = 0, n = 0, K = 0;
    cin >> T;
    while (T--)
    {
        cin >> n >> K;
        string game;
        cin >> game;
        int star = 0;
        for (int left = 0, right = 0; right < n; right++)
        {
            if (right - left + 1 == 3)
            {
                star += K;
                continue;
            }
            if (game[right] == 'W')
                star++;
            else
            {
                star--;
                left = right;
            }

        }
        cout << star << endl;
    }
    return 0;
}

*/